package Shuffle;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

public class PokeTwo {
	public String color;	//顏色
	public String number;	//數字
	public static int totalCards = 52;
	public static String cardOfColor[] 	= { "梅花", "磚塊", "愛心", "黑桃" };
	public static String cardOfNumber[] = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
	public static String allCards[] = new String[52];
		
	/**
	 * 兩張牌比大小後交換
	 */
	public static Poke[] swapCard(Poke card1,Poke card2){
		int cardOrder1 = 0;	//第一張牌的點數大小
		int cardOrder2 = 0;	//第二張牌的點數大小
		int cardColor1 = 0;	//第一張牌顏色的點數大小
		int cardColor2 = 0;	//第一張牌顏色的點數大小
		Poke[] changePoke = new Poke[2];
		Poke tempPoke = new Poke();
		
		//先比點數大小
		for(int findOrder = 0 ; findOrder < cardOfNumber.length ; findOrder++){
			if(card1.number.equals(cardOfNumber[findOrder])){
				cardOrder1 = findOrder;
			}
			if(card2.number.equals(cardOfNumber[findOrder])){
				cardOrder2 = findOrder;
			}
		}
		if(cardOrder1 > cardOrder2){
			changePoke[0] = card1;
			changePoke[1] = card2;;
		}
		//如果點數相同，比花色
		else if(cardOrder1==cardOrder2){
			for(int findColor = 0 ; findColor < cardOfColor.length ; findColor++){
				if(card1.color.equals(cardOfColor[findColor])){
					cardColor1 = findColor;
				}
				if(card2.color.equals(cardOfColor[findColor])){
					cardColor2 = findColor;
				}
			}
			if(cardColor1 > cardColor2){
				changePoke[0] = card1;
				changePoke[1] = card2;
			}else{
				changePoke[0] = card2;
				changePoke[1] = card1;
			}
		}else{
			changePoke[0] = card2;
			changePoke[1] = card1;
		}
		return changePoke;
	}
	
	public static void main(String[] args) {
		testOneCardVs();
//		testChangeCardVs();
	}
	
	/**
	 * 測試用兩張牌比大小
	 */
	public static void testChangeCardVs(){	
		Random ran = new Random();
		for(int test = 0 ; test < 10 ; test++){
			Poke card1 = new Poke();
			card1.color =cardOfColor[ran.nextInt(4)]; card1.number = cardOfNumber[ran.nextInt(13)];
			Poke card2 = new Poke();
			card2.color =cardOfColor[ran.nextInt(4)]; card2.number = cardOfNumber[ran.nextInt(13)];
			System.out.print("原本="+card1.color+card1.number +","+card2.color+card2.number+"\t");
			Poke cards[] = swapCard(card1,card2);	
			System.out.println("交換後="+cards[0].color+cards[0].number +","+cards[1].color+cards[1].number+"\n");
		}
	}
	
	/**
	 * 測試用兩張牌比大小，吐訊息出來
	 */
	public static void testOneCardVs(){	
		Random ran = new Random();
		for(int test = 0 ; test < 100 ; test++){
			Poke card1 = new Poke();
			card1.color =cardOfColor[ran.nextInt(4)]; card1.number = cardOfNumber[ran.nextInt(13)];
			Poke card2 = new Poke();
			card2.color =cardOfColor[ran.nextInt(4)]; card2.number = cardOfNumber[ran.nextInt(13)];
			System.out.println(oneVsOne(card1,card2)+"\n");
		}
	}
	
	/**
	 * 傳統兩張牌比大小
	 */
	public static String oneVsOne(Poke card1,Poke card2){
		int cardOrder1 = 0;	//第一張牌的點數大小
		int cardOrder2 = 0;	//第二張牌的點數大小
		int cardColor1 = 0;	//第一張牌顏色的點數大小
		int cardColor2 = 0;	//第一張牌顏色的點數大小
		
		//先比點數大小
		for(int findOrder = 0 ; findOrder < cardOfNumber.length ; findOrder++){
			if(card1.number.equals(cardOfNumber[findOrder])){
				cardOrder1 = findOrder;
			}
			if(card2.number.equals(cardOfNumber[findOrder])){
				cardOrder2 = findOrder;
			}
		}
		
		if(cardOrder1 > cardOrder2){
			return card1.color+card1.number+">"+card2.color+card2.number;
		}
		//如果點數相同，比花色
		else if(cardOrder1==cardOrder2){
			for(int findColor = 0 ; findColor < cardOfColor.length ; findColor++){
				if(card1.color.equals(cardOfColor[findColor])){
					cardColor1 = findColor;
				}
				if(card2.color.equals(cardOfColor[findColor])){
					cardColor2 = findColor;
				}
			}
			if(cardColor1 > cardColor2){
				return card1.color+card1.number+">"+card2.color+card2.number;
			}else{
				return card1.color+card1.number+"<"+card2.color+card2.number;
			}
		}else{
			return card1.color+card1.number+"<"+card2.color+card2.number;
		}
	}

}
